#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 4e5 + 5;
using pll = pair<ll, ll>;

ll n, k;
ll a[N], b[N], d[N];

bool check(int len) {
  stack<pll> st;
  per(i, n * 2, n + 1) {
    if (d[i] > 0)
      st.push(pll(d[i], i));
    else if (d[i] < 0) {
      ll sum = d[i];
      ll j = i;
      while (sum < 0 && st.size()) {
        pll now = st.top();
        st.pop();
        sum += now.first;
        j = now.second;
      }
      if (sum > 0) st.push(pll(sum, j));
    }
  }
  ll need = 0;
  per(i, n, 1) {
    if (d[i] > 0)
      st.push(pll(d[i], i));
    else if (d[i] < 0) {
      ll sum = d[i];
      ll j = i;
      while (sum < 0 && st.size()) {
        pll now = st.top();
        st.pop();
        if (now.second > i + len) break;
        sum += now.first;
        j = now.second;
      }
      if (sum < 0)
        need += -sum;
      else if (sum > 0)
        st.push(pll(sum, j));
    }
  }
  return need <= k;
}
int solve() {
  ll sum = accumulate(a + 1, a + n + 1, 0ll);
  if (sum <= k) return 0;
  rep(i, 1, n * 2) d[i] = b[i] - a[i];
  int l = 0, r = n - 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  return l + 1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    rep(i, 1, n) cin >> a[i];
    rep(i, 1, n) cin >> b[i];
    rep(i, 1, n) a[i + n] = a[i];
    rep(i, 1, n) b[i + n] = b[i];
    cout << solve() << endl;
  }
  return 0;
}